<?php

class UserModel extends AbstractModel
{

    protected $_companies;
    protected $_reviews;
    protected $_opinions;
    protected $_comments;

    public function setComments($comments)
    {
	$this->_comments = $comments;
    }

    public function getComments()
    {
	return $this->_comments;
    }

    public function setOpinions($opinions)
    {
	$this->_opinions = $opinions;
	return $this;
    }

    public function getOpinions()
    {
	return $this->_opinions;
    }

    public function setReviews($reviews)
    {
	$this->_reviews = $reviews;
	return $this;
    }

    public function getReviews()
    {
	return $this->_reviews;
    }

    public function getCompanies()
    {
	return $this->_companies;
    }

    public function setCompanies($companies)
    {
	$this->_companies = $companies;
	return $this;
    }

    protected function _init()
    {
	
    }

    public function getUploadPath($absolute = false)
    {
	if (!$this->id) {
	    return false;
	}
	$path = '';
	if ($absolute) {
	    $path = Yii::app()->params['uploadDir'] . DIRECTORY_SEPARATOR;
	}
	$path .= ceil($this->getId() / 100) . DIRECTORY_SEPARATOR . $this->getId();
	return $path;
    }

    public function getAvatar()
    {
	$path = implode(DIRECTORY_SEPARATOR, array(
	    Yii::app()->params['uploadDirectory'],
	    $this->getUploadPath(),
	    'avatar',
	    Yii::app()->params['avatar']['width'] . '_' . Yii::app()->params['avatar']['height'] . '.' . $this->getDbData('avatar_ext'),
		));
	if (file_exists($_SERVER['DOCUMENT_ROOT'] . $path)) {
	    return $path;
	}

	if (isset(Yii::app()->params['defaultAvatar'][Yii::app()->params['avatar']['width']])) {
	    return Yii::app()->params['defaultAvatar'][Yii::app()->params['avatar']['width']];
	}
    }

    public function getProfileName()
    {
	return $this->getDbData('profile_name') ? $this->getDbData('profile_name') : $this->getDbData('login');
    }

    public function getAvatarThumb()
    {
	$path = implode(DIRECTORY_SEPARATOR, array(
	    Yii::app()->params['uploadDirectory'],
	    $this->getUploadPath(),
	    'avatar',
	    Yii::app()->params['avatar']['thumbWidth'] . '_' . Yii::app()->params['avatar']['thumbHeight'] . '.' . $this->getDbData('avatar_ext'),
		));
	if (file_exists($_SERVER['DOCUMENT_ROOT'] . $path)) {
	    return $path;
	}
	if (isset(Yii::app()->params['defaultAvatar'][Yii::app()->params['avatar']['thumbWidth']])) {
	    return Yii::app()->params['defaultAvatar'][Yii::app()->params['avatar']['thumbWidth']];
	}
    }

}